package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.JToggleButton;
import javax.swing.JList;
import java.awt.Color;
import javax.swing.JEditorPane;
import javax.swing.ListSelectionModel;
import java.awt.TextArea;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import ocsf.server.ConnectionToClient;
import messages.LoginMessage;
import controllers.DBController;

public class CustomerComplaint extends JFrame {
	
	LoginMessage loginMsg;
	DBController dbController;
	ConnectionToClient connection;
	private JPanel contentPane;
	private JTextField textField;
	private JTextField textFieldComp;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CustomerComplaint frame = new CustomerComplaint();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CustomerComplaint() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 596, 335);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JButton btnConf = new JButton("Confirm");
		btnConf.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {            /*login button action */
				try{
					btnConfActionPerformed(e);	
				}catch(IOException | SQLException e1) {
					e1.printStackTrace();
				}
			}			
		});
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				CustomerComplaint.this.setVisible(false);

			}
		});
		
		JLabel lblComplaint = new JLabel("Complaint");
		lblComplaint.setFont(new Font("Tahoma", Font.ITALIC, 18));
		
		JLabel lblYourEmail = new JLabel("Your Email");
		
		textField = new JTextField();
		textField.setColumns(10);
		
		textFieldComp = new JTextField();
		textFieldComp.setHorizontalAlignment(SwingConstants.LEFT);
		textFieldComp.setToolTipText("");
		textFieldComp.setColumns(10);
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(24)
					.addComponent(lblYourEmail)
					.addContainerGap(497, Short.MAX_VALUE))
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addContainerGap(294, Short.MAX_VALUE)
					.addComponent(btnConf)
					.addGap(49)
					.addComponent(btnCancel)
					.addGap(93))
				.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(lblComplaint, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
							.addGap(137))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED, 142, Short.MAX_VALUE)
							.addComponent(textFieldComp, GroupLayout.PREFERRED_SIZE, 261, GroupLayout.PREFERRED_SIZE)))
					.addGap(71))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addGap(56)
					.addComponent(lblYourEmail)
					.addGap(30)
					.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(169))
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblComplaint)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(textFieldComp, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnConf)
						.addComponent(btnCancel))
					.addContainerGap(72, Short.MAX_VALUE))
		);
		contentPane.setLayout(gl_contentPane);
	}
	
	private void btnConfActionPerformed(ActionEvent ev) throws IOException, SQLException {
		
		ArrayList<String> arr=new ArrayList<String>();
		String complain=textFieldComp.getText();
		String mail=textField.getText();
		arr.add("Complaint");
		arr.add(complain);
		arr.add(mail);
		connection= new ConnectionToClient();
		loginMsg=new LoginMessage();
		connection=loginMsg.getClient();
		dbController=new DBController(arr,connection );
		
	}
}
